package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Construction;
import com.ruoyi.system.service.IConstructionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 施工Controller
 *
 * @author ruoyi
 * @date 2021-06-22
 */
@RestController
@RequestMapping("/system/construction")
public class ConstructionController extends BaseController {
    @Autowired
    private IConstructionService constructionService;

    /**
     * 查询施工列表
     */
//    @PreAuthorize("@ss.hasPermi('system:construction:list')")
    @GetMapping("/list")
    public TableDataInfo list(Construction construction) {
        startPage();
        List<Construction> list = constructionService.selectConstructionList(construction);
        return getDataTable(list);
    }

    /**
     * 导出施工列表
     */
//    @PreAuthorize("@ss.hasPermi('system:construction:export')")
    @Log(title = "施工", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Construction construction) {
        List<Construction> list = constructionService.selectConstructionList(construction);
        ExcelUtil<Construction> util = new ExcelUtil<Construction>(Construction.class);
        return util.exportExcel(list, "construction");
    }

    /**
     * 获取施工详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:construction:query')")
    @GetMapping(value = "/{cId}")
    public AjaxResult getInfo(@PathVariable("cId") Long cId) {
        return AjaxResult.success(constructionService.selectConstructionById(cId));
    }

    /**
     * 新增施工
     */
//    @PreAuthorize("@ss.hasPermi('system:construction:add')")
    @Log(title = "施工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Construction construction) {
        construction.setcCreatetime(new Date());
        construction.setcState("0");
        constructionService.insertConstruction(construction);
        return AjaxResult.success(construction);
    }

    /**
     * 修改施工
     */
//    @PreAuthorize("@ss.hasPermi('system:construction:edit')")
    @Log(title = "施工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Construction construction) {
        return toAjax(constructionService.updateConstruction(construction));
    }

    /**
     * 删除施工
     */
//    @PreAuthorize("@ss.hasPermi('system:construction:remove')")
    @Log(title = "施工", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cIds}")
    public AjaxResult remove(@PathVariable Long[] cIds) {
        return toAjax(constructionService.deleteConstructionByIds(cIds));
    }
}
